home *** CD-ROM | disk | FTP | other *** search
/ God is Closer Than You Think / God is Closer.iso / pc / assets / lmc_tween.as next >
Text File  |  2005-01-20  |  5KB  |  142 lines

  1. ╘¬°/*
  2. tweening prototypes
  3. version 1.0
  4. Ladislav Zigo,lacoz@inmail.sk
  5. */
  6. com.robertpenner.easing.Back;
  7. com.robertpenner.easing.Bounce;
  8. com.robertpenner.easing.Circ;
  9. com.robertpenner.easing.Cubic;
  10. com.robertpenner.easing.Elastic;
  11. com.robertpenner.easing.Expo;
  12. com.robertpenner.easing.Linear;
  13. com.robertpenner.easing.Quad;
  14. com.robertpenner.easing.Quart;
  15. com.robertpenner.easing.Quint;
  16. com.robertpenner.easing.Sine;
  17.  
  18. mx.transitions.easing.Back;
  19. mx.transitions.easing.Bounce;
  20. mx.transitions.easing.Elastic;
  21. mx.transitions.easing.None;
  22. mx.transitions.easing.Strong;
  23. mx.transitions.easing.Regular;
  24. // == core methods ==
  25. MovieClip.prototype.tween = function(props, pEnd, seconds, animType,
  26.                 delay, callback, extra1, extra2) {
  27.     if (arguments.length<2) {
  28.         trace("error: props & pEnd must be defined");
  29.         return;
  30.     }
  31.     // parse arguments to valid type:
  32.     // parse properties
  33.     if (typeof (props) == "string") {
  34.         props = [props];
  35.     }
  36.     // parse end values
  37.     // if pEnd is not array 
  38.     if (pEnd.length == undefined ) {
  39.         pEnd = [pEnd];
  40.     } 
  41.     // parse time properties
  42.     if (seconds<0.01 || seconds == undefined) {
  43.         seconds = 2;
  44.     }
  45.     if (delay<0.01 || delay == undefined) {
  46.         delay = 0;
  47.     }
  48.     var now = getTimer();
  49.     var tstart = now+delay*1000;
  50.     var tend = tstart+seconds*1000;
  51.     // parse animtype to reference to equation function 
  52.     animType = animType.toLowerCase();
  53.     if (animType == "linear") {
  54.         var eqf = mx.transitions.easing.None.easeNone;
  55.     } else if (animType.indexOf("easeinout") == 0) {
  56.         var t = animType.substr(9);
  57.         t = t.charAt(0).toUpperCase()+t.substr(1);
  58.         var eqf = com.robertpenner.easing[t].easeInOut;
  59.         if(eqf == undefined){
  60.         var eqf = mx.transitions.easing[t].easeInOut;    
  61.         }
  62.     } else if (animType.indexOf("easein") == 0) {
  63.         var t = animType.substr(6);
  64.         t = t.charAt(0).toUpperCase()+t.substr(1);
  65.         var eqf = com.robertpenner.easing[t].easeIn;
  66.         if(eqf == undefined){
  67.         var eqf = mx.transitions.easing[t].easeIn;    
  68.         }
  69.     } else if (animType.indexOf("easeout") == 0) {
  70.         var t = animType.substr(7);
  71.         t = t.charAt(0).toUpperCase()+t.substr(1);
  72.         var eqf = com.robertpenner.easing[t].easeOut;
  73.         if(eqf == undefined){
  74.         var eqf = mx.transitions.easing[t].easeOut;    
  75.         }
  76.     }
  77.     if (eqf == undefined) {
  78.         // set default tweening equation
  79.         var eqf = mx.transitions.easing.Strong.easeOut;
  80.     }
  81.     // parse callback function
  82.     if (typeof (callback) == "function") {
  83.         callback = {func:callback, scope:this._parent};
  84.     }
  85.     // pass parameters to tweenManager static method 
  86.     tweenManager.addTween(this, props, pEnd, seconds, delay, eqf, callback, extra1, extra2);
  87. };
  88. ASSetPropFlags(MovieClip.prototype, "tween", 1, 0);
  89. MovieClip.prototype.stopTween = function(props) {
  90.     if (typeof (props) == "string") {
  91.         props = [props];
  92.     }
  93.     tweenManager.removeTween(this, props);
  94. };
  95. ASSetPropFlags(MovieClip.prototype, "stopTween", 1, 0);
  96. MovieClip.prototype.isTweening = function() {
  97.     //returns boolean
  98.     return tweenManager.isTweening(this);
  99. };
  100. ASSetPropFlags(MovieClip.prototype, "isTweening", 1, 0);
  101. MovieClip.prototype.getTweens = function() {
  102.     // returns count of running tweens
  103.     return tweenManager.getTweens(this);
  104. };
  105. ASSetPropFlags(MovieClip.prototype, "getTweens", 1, 0);
  106. //
  107. // == shortcut methods == 
  108. // these methods only passes parameters to tween method
  109. MovieClip.prototype.alphaTo = function (destAlpha, seconds, animType, delay, callback, extra1, extra2) {
  110.     this.tween(["_alpha"],[destAlpha],seconds,animType,delay,callback,extra1,extra2)
  111. }
  112. ASSetPropFlags(MovieClip.prototype, "alphaTo", 1, 0);
  113. MovieClip.prototype.colorTo = function (destColor, seconds, animType, delay, callback, extra1, extra2) {
  114.     // destionation color transform matrix
  115.     var destCt = {rb: destColor >> 16, ra:0,
  116.                   gb: (destColor & 0x00FF00) >> 8, ga:0,
  117.                   bb: destColor & 0x0000FF,ba:0}
  118.     //
  119.     this.tween(["_ct_"],[destCt],seconds,animType,delay,callback,extra1,extra2)
  120. }
  121. ASSetPropFlags(MovieClip.prototype, "colorTo", 1, 0);
  122. MovieClip.prototype.colorTransformTo = function (ra, rb, ga, gb, ba, bb, aa, ab, timeSeconds, animType, delay, callback, extra1, extra2) {
  123.     // destionation color transform matrix
  124.     var destCt = {ra: ra ,rb: rb , ga: ga, gb: gb, ba: ba, bb: bb, aa: aa, ab: ab}
  125.     //
  126.     this.tween(["_ct_"],[destCt],seconds,animType,delay,callback,extra1,extra2)
  127. }
  128. ASSetPropFlags(MovieClip.prototype, "colorTransformTo", 1, 0);
  129. MovieClip.prototype.scaleTo = function (destScale, seconds, animType, delay, callback, extra1, extra2) {
  130.     this.tween(["_xscale", "_yscale"],[destScale, destScale],seconds,animType,delay,callback,extra1,extra2)
  131. }
  132. ASSetPropFlags(MovieClip.prototype, "scaleTo", 1, 0);
  133. MovieClip.prototype.slideTo = function (destX, destY, seconds, animType, delay, callback, extra1, extra2) {
  134.     this.tween(["_x", "_y"],[destX, destY],seconds,animType,delay,callback,extra1,extra2)
  135. }
  136. ASSetPropFlags(MovieClip.prototype, "slideTo", 1, 0);
  137. MovieClip.prototype.rotateTo = function (destRotation, seconds, animType, delay, callback, extra1, extra2) {
  138.     this.tween(["_rotation"],[destRotation],seconds,animType,delay,callback,extra1,extra2)
  139. }
  140. ASSetPropFlags(MovieClip.prototype, "rotateTo", 1, 0);
  141.  
  142.